package com.cysyz.mylib.domain;

import com.cysyz.mylib.domain.annotation.Alias;
import com.cysyz.mylib.utils.DateUtil;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

/**
 * Created by jiaoyujia on 2015/1/15.
 */
@MappedSuperclass
public class CommonUser extends CreateTimeRegisterEntity implements ICommonUser {


    //alias
    public static final String TABLE_ALIAS = "SysUser";
    public static final String ALIAS_ID = "id";
    public static final String ALIAS_VERSION = "version";
    public static final String ALIAS_CREATE_TIME = "createTime";
    public static final String ALIAS_EMAIL = "email";
    public static final String ALIAS_LAST_LOGIN_IP = "lastLoginIp";
    public static final String ALIAS_LAST_LOGIN_TIME = "lastLoginTime";
    public static final String ALIAS_LOGIN_COUNT = "loginCount";
    public static final String ALIAS_LOGIN_NAME = "loginName";
    public static final String ALIAS_MOBILE = "mobile";
    public static final String ALIAS_NAME = "name";
    public static final String ALIAS_PASSWORD = "password";
    public static final String ALIAS_STATE = "state";
    public static final String ALIAS_ROLE_HAS_THIS_USER = "roleHasThisUser";

    //date formats
    public static final String FORMAT_CREATE_TIME = DATE_FORMAT;
    public static final String FORMAT_LAST_LOGIN_TIME = DATE_TIME_FORMAT;


    //可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息

    @Email @Length(max=50)
    @Column(name = "EMAIL", unique = false, nullable = true, length = 50)
    @Alias(cn="邮箱")
    private java.lang.String email;

    @Length(max=255)
    @Column(name = "LAST_LOGIN_IP", unique = false, nullable = true, length = 255)
    @Alias(cn="最后登陆IP")
    private java.lang.String lastLoginIp;


    @Column(name = "LAST_LOGIN_TIME", unique = false, nullable = true, length = 19)
    @Alias(cn="最后登录时间")
    private java.util.Date lastLoginTime;


    @Column(name = "LOGIN_COUNT", unique = false, nullable = true, length = 10)
    @Alias(cn="登录次数")
    private java.lang.Integer loginCount = 0;

    @Length(max=30)
    @Column(name = "LOGIN_NAME", unique = false, nullable = false, length = 30)
    @Alias(cn="用户名")
    private java.lang.String loginName;

    @Length(max=11)
    @Column(name = "MOBILE", unique = false, nullable = true, length = 50)
    @Alias(cn="手机号码")
    private java.lang.String mobile;

    @Length(max=50)
    @Column(name = "NAME", unique = false, nullable = true, length = 50)
    @Alias(cn="姓名")
    private java.lang.String name;

    @Length(max=50)
    @Column(name = "PASSWORD", unique = false, nullable = false, length = 50)
    @Alias(cn="密码")
    private java.lang.String password;

    @Length(max=10)
    @Column(name = "STATE", unique = false, nullable = true, length = 10)
    @Alias(cn="状态")
    private java.lang.String state;

    //columns END



    @Override
    public java.lang.String getEmail() {
        return this.email;
    }

    @Override
    public void setEmail(java.lang.String value) {
        this.email = value;
    }

    @Override
    public java.lang.String getLastLoginIp() {
        return this.lastLoginIp;
    }

    @Override
    public void setLastLoginIp(java.lang.String value) {
        this.lastLoginIp = value;
    }

    @Override
    @Transient
    public String getLastLoginTimeString() {
        return DateUtil.format(getLastLoginTime(), FORMAT_LAST_LOGIN_TIME);
    }

    @Override
    public java.util.Date getLastLoginTime() {
        return this.lastLoginTime;
    }

    @Override
    public void setLastLoginTime(java.util.Date value) {
        this.lastLoginTime = value;
    }

    @Override
    public java.lang.Integer getLoginCount() {
        return this.loginCount;
    }

    @Override
    public void setLoginCount(java.lang.Integer value) {
        this.loginCount = value;
    }

    @Override
    public java.lang.String getLoginName() {
        return this.loginName;
    }

    @Override
    public void setLoginName(java.lang.String value) {
        this.loginName = value;
    }

    @Override
    public java.lang.String getMobile() {
        return this.mobile;
    }

    @Override
    public void setMobile(java.lang.String value) {
        this.mobile = value;
    }

    @Override
    public java.lang.String getName() {
        return this.name;
    }

    @Override
    public void setName(java.lang.String value) {
        this.name = value;
    }

    @Override
    public java.lang.String getPassword() {
        return this.password;
    }

    @Override
    public void setPassword(java.lang.String value) {
        this.password = value;
    }

    @Override
    public java.lang.String getState() {
        return this.state;
    }

    @Override
    public void setState(java.lang.String value) {
        this.state = value;
    }

	/*vo*/


    @Transient
    private java.util.Date createTimeBegin;
    @Transient
    private java.util.Date createTimeEnd;



    @Transient
    private java.util.Date lastLoginTimeBegin;
    @Transient
    private java.util.Date lastLoginTimeEnd;

    @Transient
    private java.lang.Integer loginCountMin;
    @Transient
    private java.lang.Integer loginCountMax;







    @Override
    @Transient
    public java.util.Date getCreateTimeBegin() {
        return this.createTimeBegin;
    }

    @Override
    public void setCreateTimeBegin(java.util.Date value) {
        this.createTimeBegin = value;
    }

    @Override
    @Transient
    public java.util.Date getCreateTimeEnd() {
        return this.createTimeEnd;
    }

    @Override
    public void setCreateTimeEnd(java.util.Date value) {
        this.createTimeEnd = value;
    }
    @Override
    @Transient
    public java.util.Date getLastLoginTimeBegin() {
        return this.lastLoginTimeBegin;
    }

    @Override
    public void setLastLoginTimeBegin(java.util.Date value) {
        this.lastLoginTimeBegin = value;
    }

    @Override
    @Transient
    public java.util.Date getLastLoginTimeEnd() {
        return this.lastLoginTimeEnd;
    }

    @Override
    public void setLastLoginTimeEnd(java.util.Date value) {
        this.lastLoginTimeEnd = value;
    }
    @Override
    public java.lang.Integer getLoginCountMin() {
        return this.loginCountMin;
    }

    @Override
    public void setLoginCountMin(java.lang.Integer value) {
        this.loginCountMin = value;
    }

    @Override
    @Transient
    public java.lang.Integer getLoginCountMax() {
        return this.loginCountMax;
    }

    @Override
    public void setLoginCountMax(java.lang.Integer value) {
        this.loginCountMax = value;
    }




    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("Id", getId())
                .append("Version",getVersion())
                .append("CreateTime",getCreateTime())
                .append("Email",getEmail())
                .append("LastLoginIp",getLastLoginIp())
                .append("LastLoginTime",getLastLoginTime())
                .append("LoginCount",getLoginCount())
                .append("LoginName",getLoginName())
                .append("Mobile",getMobile())
                .append("Name",getName())
                .append("Password",getPassword())
                .append("State",getState())
                .toString();
    }
}
